@extends('layouts.master')

@section('title')
    商品录入——钢链网管理后台
@stop

@section('app_css')
    <link rel="stylesheet" href="/resource/css/bootstrap.min.css">
    <link rel="stylesheet" href="/resource/css/font-awesome.min.css">
    <link rel="stylesheet" href="/resource/css/animate.min.css">
    <link rel="stylesheet" href="/resource/css/custom.css">
    <link rel="stylesheet" href="/resource/css/green.css">
    <link rel="stylesheet" href="/resource/css/fileinput.min.css">
    @stop

@section('app_js')
    <!--[if lt IE 9]>
    <script type="text/javascript" src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script type="text/javascript" src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript" src="/resource/js/jquery.min.js"></script>
    <script type="text/javascript" src="/resource/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/resource/js/custom.js"></script>
    <!-- icheck -->
    <script type="text/javascript" src="/resource/js/icheck.min.js"></script>
    <!-- Datatables -->
    <script type="text/javascript" src="/resource/js/jquery.dataTables.js"></script>
    <script type="text/javascript" src="/resource/js/J_main.js"></script>
    <!-- 添加图片 -->
    <script type="text/javascript" src="/resource/js/fileinput.min.js"></script>
    <script type="text/javascript" src="/resource/js/fileinput_locale_zh.js"></script>
    <script type="text/javascript" src="/resource/js/T.js"></script>
   <script type="text/javascript">
       {{-- ajax规格 --}}
       $('#product_spec').after('<div class="col-md-10 col-sm-10 col-xs-12" id="product_spec_sec"><select name="product_spec" class="form-control col-md-7 col-xs-12"></select></div>');
       $('#product_spec_sec').hide();
       $('[name="product_brand"]').change(function(){
           var cate_id = $(this).children('option:selected').attr('rel');
           var str = "";
           $('#product_spec').hide();
           $.ajax({
               'url':'get_spec',
               'type':'get',
               'data':'id='+cate_id,
               success: function(data){
                   console.log(data);
                   $.each(data.spec_list,function(index,arr){
                       str += "<option value="+arr.spec_name+">"+arr.spec_name+"</option>";
                   });
                   $('#category').val(data.cate_id);
                   $('#product_spec_sec').show().children('select').html(str);
               }
           });

       })
       {{----}}
       $('input.form-control').after("<span style='color:red;'></span>");
       $(document).delegate('.btn-success','click',function(){
           if($("[name='product_brand']").val() == ""){
               alert("请选择品名");
               return false;
           };
           if($("[name='product_material']").val() == ""){
               alert("请选择材质");
               return false;
           };

           if($("[name='storage']").val() == ""){
               alert("请选择仓库");
               return false;
           };
           if($("[name='factory']").val() == ""){
               alert("请选择钢厂");
               return false;
           };
           for (var i = 0; i < $('input.form-control').length; i++) {

               if($('input.form-control').eq(i).val() == ''){
                   $('input.form-control').eq(i).focus().siblings('span').show().html('不能为空');
                   return false;
               }else{
                   var reg = /^[0-9/.]*$/;
                   if(!reg.test($('input.form-control').eq(0).val())){
                       alert("价格格式不正确");
                       return false;
                   }else if(!reg.test($('input.form-control').eq(1).val())){
                       alert($('input.form-control').eq(1).val());
                       alert("库存格式不正确");
                       return false;
                   }else if(!reg.test($('input.form-control').eq(2).val())){
                       alert($('input.form-control').eq(2).val());
                       alert("件重格式不正确");
                       return false;
                   }else{
                       $('input.form-control').eq(i).siblings('span').hide();
                       return true;
                   }

               };
           };
       })
    </script>
@stop

@section('content')
    <body class="nav-md">

    <div class="container body">


        <div class="main_container">

            @include('common.admin_menu')

                    <!-- top navigation -->
            @include('common.admin_nav')
                    <!-- /top navigation -->


            <!-- page content -->
            <div class="right_col" role="main">

                <div class="">

                    <div class="row cont">

                        <div class="col-md-6 col-sm-12 col-xs-12">
                            <div class="x_panel">
                                <div class="x_title">
                                    <h2>商品录入<small>商品管理</small></h2>
                                    <div class="clearfix"></div>
                                </div>

                                <div class="x_content">
                                    <br />

                                    @if(empty($product))
                                        {{ Form::open(['url'=>'/admin/product_import_action', 'id'=>'demo-form2', 'class'=> 'form-horizontal form-label-left', 'files' => true, 'method' => 'post']) }}
                                        <div class="form-group">
                                            <input id="category" type="hidden" name="category"/>
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">品名</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <select name="product_brand" class="form-control col-md-7 col-xs-12">
                                                    <option value="">请选择</option>
                                                    @foreach($brand as $v)
                                                        <option value="{{$v->brand_id}}" rel="{{$v->cate_id}}">{{$v->brand_name}}</option>
                                                    @endforeach
                                                </select>
                                                <span style="color: #ff0000"></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">材质</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <select name="product_material" class="form-control col-md-7 col-xs-12">
                                                    <option value="">请选择</option>
                                                    @foreach($material as $v)
                                                        <option value="{{$v->m_id}}">{{$v->m_name}}</option>
                                                    @endforeach
                                                </select>

                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-2 col-sm-2 col-xs-12" for="first-name">商品单价
                                            </label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <input name="product_price" type="text" id="first-name" required="required" class="form-control col-md-7 col-xs-12">

                                            </div>

                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">规格</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12" id="product_spec">
                                                <select name="product_spec" class="form-control col-md-7 col-xs-12"></select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">库存</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <input name="real_stock" class="form-control col-md-7 col-xs-12" type="text">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">件重（吨）</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <input name="piece_weight" class="form-control col-md-7 col-xs-12" type="text">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">仓库</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <select name="storage" class="form-control col-md-7 col-xs-12">
                                                    <option value="">请选择</option>
                                                    @foreach($storage as $v)
                                                        <option value="{{$v->storage_id}}">{{$v->storage_name}}</option>
                                                    @endforeach
                                                </select>
                                                <span style="color: #ff0000"></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">钢厂</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <select name="factory" class="form-control col-md-7 col-xs-12">
                                                    <option value="">请选择</option>
                                                    @foreach($factory as $v)
                                                        <option value="{{$v->factory_id}}">{{$v->factory_name}}</option>
                                                    @endforeach
                                                </select>
                                                <span style="color: #ff0000"></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">负责人</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <input name="duty_people" class="form-control col-md-7 col-xs-12" type="text">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">商品备注</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <textarea name="remarks" class="form-control col-md-7 col-xs-12"></textarea>
                                            </div>
                                        </div>

                                        <div class="ln_solid"></div>
                                        <div class="form-group">
                                            <div class="col-md-10 col-sm-10 col-xs-12 col-md-offset-3">
                                                <button type="reset" class="btn btn-primary">取消</button>
                                                <button type="submit" class="btn btn-success">提交</button>
                                            </div>
                                        </div>

                                        {{ Form::close() }}
                                    @else
                                        {{ Form::open(['url'=>'/admin/product_import_action', 'id'=>'demo-form2', 'class'=> 'form-horizontal form-label-left', 'files' => true, 'method' => 'post']) }}
                                        <input type="hidden" value="{{$product->product_id}}" name="product_id">
                                        <input type="hidden" id="category" value="{{$product->category}}" name="category">


                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">品名</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <select name="product_brand" class="form-control col-md-7 col-xs-12">
                                                    <option value="">请选择</option>
                                                    @foreach($brand as $v)
                                                        <option value="{{$v->brand_id}}" rel="{{$v->cate_id}}" @if($product->product_brand == $v->brand_id)selected @endif>{{$v->brand_name}}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">品名</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <select name="product_material" class="form-control col-md-7 col-xs-12">
                                                    <option value="">请选择</option>
                                                    @foreach($material as $v)
                                                        <option value="{{$v->m_id}}" @if($product->product_material == $v->m_id)selected @endif>{{$v->m_name}}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-2 col-sm-2 col-xs-12" for="first-name">商品单价
                                            </label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <input name="product_price" type="text" id="first-name" required="required" class="form-control col-md-7 col-xs-12" value="{{$product->product_price}}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12" >规格</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12" id="product_spec">
                                                <select name="product_spec" class="form-control col-md-7 col-xs-12">
                                                    @foreach($spec['spec_list'] as $v)
                                                        <option value="{{$v->spec_name}}" @if($product->product_spec == $v->spec_name)selected @endif>{{$v->spec_name}}</option>
                                                    @endforeach
                                                </select>
                                                {{--<input name="product_spec" class="form-control col-md-7 col-xs-12" type="text"  value="{{$product->product_spec}}">--}}
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">库存</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <input name="real_stock" class="form-control col-md-7 col-xs-12" type="text"  value="{{$product->real_stock}}">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">件重（吨）</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <input name="piece_weight" class="form-control col-md-7 col-xs-12" type="text"  value="{{$product->piece_weight}}">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">仓库</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <select name="storage" class="form-control col-md-7 col-xs-12">
                                                    <option value="">请选择</option>
                                                    @foreach($storage as $v)
                                                        <option value="{{$v->storage_id}}" @if($product->storage == $v->storage_id)selected @endif>{{$v->storage_name}}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">钢厂</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <select name="factory" class="form-control col-md-7 col-xs-12">
                                                    <option value="">请选择</option>
                                                    @foreach($factory as $v)
                                                        <option value="{{$v->factory_id}}" @if($product->factory == $v->factory_id)selected @endif>{{$v->factory_name}}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">负责人</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <input name="duty_people" class="form-control col-md-7 col-xs-12" type="text"  value="{{$product->duty_people}}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="middle-name" class="control-label col-md-2 col-sm-2 col-xs-12">商品备注</label>
                                            <div class="col-md-10 col-sm-10 col-xs-12">
                                                <textarea name="remarks" class="form-control col-md-7 col-xs-12"> {{$product->remarks}}</textarea>
                                            </div>
                                        </div>

                                        <div class="ln_solid"></div>
                                        <div class="form-group">
                                            <div class="col-md-10 col-sm-10 col-xs-12 col-md-offset-3">
                                                <button type="reset" class="btn btn-primary">取消</button>
                                                <button type="submit" class="btn btn-success">提交</button>
                                            </div>
                                        </div>


                                        {{ Form::close() }}
                                    @endif
                                </div>
                            </div>
                        </div>

                        <br />
                        <br />
                        <br />

                    </div>
                </div>

                <!-- footer content -->

                <footer>
                    <div class="">
                        <p class="pull-right">Copyright 2016 ganglianw.com All rights reserved. |
                            <span class="lead"> <i class="fa fa-logo-footer"></i> 钢链网后台管理系统</span>
                        </p>
                    </div>
                    <div class="clearfix"></div>
                </footer>
                <!-- /footer content -->
            </div>
            <!-- /page content -->

        </div>
    </div>

    <div id="custom_notifications" class="custom-notifications dsp_none">
        <ul class="list-unstyled notifications clearfix" data-tabbed_notifications="notif-group">
        </ul>
        <div class="clearfix"></div>
        <div id="notif-group" class="tabbed_notifications"></div>
    </div>
    </body>
@stop